package com.hc.testaudio.base;

import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;

import com.yc.yclibrary.base.YcAppCompatActivity;
import com.yc.yclibx.YcManage;
import com.yc.yclibx.bean.YcForResultBean;
import com.yc.yclibx.toactivity.YcForResult;

import java.util.Stack;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 *
 */
public abstract class BaseActivity extends YcAppCompatActivity {
    protected Stack<Disposable> mDisposableList = new Stack<>();
    protected YcManage mYcManage = new YcManage();//用于关闭
    protected TextView mActionMid;
    protected ImageView mActionLeftIv;
    protected TextView mActionRightTv;
    protected ImageView mActionRightIv;


    public void startActivityForResult(Intent intent, Consumer<YcForResultBean> consumer) {
        YcForResult ycForResult = new YcForResult(getActivity());
        Disposable disposable = ycForResult.start(intent).subscribe(consumer);
        addDisposable(disposable);
    }

    public void addDisposable(Disposable disposable) {
        mDisposableList.add(disposable);
    }

    public BaseActivity getActivity() {
        return this;
    }

    @Override
    protected void onDestroy() {
        mYcManage.removeAll();
        for (Disposable disposable : mDisposableList) {
            disposable.dispose();
        }
        super.onDestroy();
    }

    public YcManage getYcManage() {
        return mYcManage;
    }

//    public void showErrorDialog(String errorMsg) {
//        new CommonDialog(getActivity(), mYcManage)
//                .setMsg(errorMsg)
//                .setSingleBtnText("确定")
//                .setSingleOnClick(v -> finish()).showSingle();
//    }
}
